package net.opentsdb.plugin.enums;

import net.opentsdb.auth.Authentication;
import net.opentsdb.core.WriteableDataPointFilterPlugin;
import net.opentsdb.meta.MetaDataCache;
import net.opentsdb.meta.TsuidDelete;
import net.opentsdb.search.SearchPlugin;
import net.opentsdb.tsd.RTPublisher;
import net.opentsdb.tsd.StorageExceptionHandler;
import net.opentsdb.uid.UniqueIdFilterPlugin;

import java.util.HashSet;
import java.util.Set;

public enum PluginStates {

    AuthenticationState("tsd.core.authentication.enable","tsd.core.authentication.plugin",Authentication.class),
    Search("tsd.search.enable","tsd.search.plugin",SearchPlugin.class),
    Rtpublisher("tsd.rtpublisher.enable","tsd.rtpublisher.plugin",RTPublisher.class),
    Cache("tsd.core.meta.cache.enable","tsd.core.meta.cache.plugin",MetaDataCache.class),
    Storage_exception_handler("tsd.core.storage_exception_handler.enable","tsd.core.storage_exception_handler.plugin",StorageExceptionHandler.class),
    Timeseriesfilter("tsd.timeseriesfilter.enable","tsd.timeseriesfilter.plugin",WriteableDataPointFilterPlugin.class),
    Uidfilter("tsd.uidfilter.enable","tsd.uidfilter.plugin",UniqueIdFilterPlugin.class),
    TsuidDel("tsd.tsuiddel.enable","tsd.tsuiddel.plugin",TsuidDelete.class);

    private String name;
    private String plugin;
    private Class clazz;

    public String getName() {
        return name;
    }

    public String getPlugin() {
        return plugin;
    }

    public Class getClazz() {
        return clazz;
    }

    PluginStates(String name, String plugin, Class clazz){
        this.name = name;
        this.plugin = plugin;
        this.clazz = clazz;
    }

    public static Set<String> getEnables(){
        Set<String> enables = new HashSet<>();
        for(PluginStates state : PluginStates.values()){
            enables.add(state.getName());
        }

        return enables;
    }

    public static PluginStates byClazz(Class clazz){
        for(PluginStates state : PluginStates.values()){
            if(state.getClazz().equals(clazz))
                return state;
        }

        return null;
    }
}
